package com.kfyang.manualgear.daoplugin.simple;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

public class SimpleSyntaxHighlighter extends SyntaxHighlighterBase {
    public static final TextAttributesKey SEPARATOR =
        createTextAttributesKey("SIMPLE_SEPARATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
    public static final TextAttributesKey KEYWORD =
        createTextAttributesKey("SIMPLE_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
    public static final TextAttributesKey EXPRESSION =
        createTextAttributesKey("SIMPLE_EXPRESSION", DefaultLanguageHighlighterColors.LOCAL_VARIABLE);
    public static final TextAttributesKey FRAG =
        createTextAttributesKey("SIMPLE_FRAG", DefaultLanguageHighlighterColors.INSTANCE_FIELD);
    public static final TextAttributesKey COMMENT =
        createTextAttributesKey("SIMPLE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
    public static final TextAttributesKey OTHER =
        createTextAttributesKey("SIMPLE_OTHER", DefaultLanguageHighlighterColors.STRING);
    public static final TextAttributesKey BAD_CHARACTER =
        createTextAttributesKey("SIMPLE_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);


    private static final TextAttributesKey[] BAD_CHAR_KEYS = {BAD_CHARACTER};
    private static final TextAttributesKey[] KEY_KEYS = {KEYWORD};
    private static final TextAttributesKey[] OTHER_KEYS = {OTHER};
    private static final TextAttributesKey[] EXPRESSION_KEYS = {EXPRESSION};
    private static final TextAttributesKey[] FRAG_KEYS = {FRAG};
    private static final TextAttributesKey[] COMMENT_KEYS = {COMMENT};
    private static final TextAttributesKey[] EMPTY_KEYS = {};

    @NotNull
    @Override
    public Lexer getHighlightingLexer() {
        return new SimpleLexerAdapter();
    }

    @Override
    public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) {
        if (tokenType.equals(SimpleTypes.KEYWORD)) {
            return KEY_KEYS;
        }
        if (tokenType.equals(SimpleTypes.EXPRESSION) || tokenType.equals(SimpleTypes.IN_EXPRESSION)) {
            return EXPRESSION_KEYS;
        }
        if (tokenType.equals(SimpleTypes.FRAG)) {
            return FRAG_KEYS;
        }
        if (tokenType.equals(SimpleTypes.OTHER)) {
            return OTHER_KEYS;
        }
        if (tokenType.equals(SimpleTypes.COMMENT)) {
            return COMMENT_KEYS;
        }
        if (tokenType.equals(TokenType.BAD_CHARACTER)) {
            return BAD_CHAR_KEYS;
        }
        return EMPTY_KEYS;
    }

}
